home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ansi / use2crts.zip / FLIPDOOR.ASM < prev    next >
Assembly Source File  |  1986-11-02  |  7KB  |  234 lines

  1. ;RECOVERED FROM THE DEFECTIVE USE2CRTS.LBR
  2. title     FLIPDOOR.ASM - Switch Color/Mono Screens on Keyboard Request
  3. ;            and change active pages on color monitor.
  4. ;
  5. ;fixed to work with masm 4 (PTRs added)
  6. ;
  7. ; Courtesy of The Consultants' Exchange BBS (714) 842-6348
  8. ;    Adapted from DOORS.ASM written by John Dickenson; Published in the
  9. ;Feb. 5, 1985 issue of PC Magazine Volume 4 Number 3, pp 273-277, and FLIP.ASM
  10. ;From the Feb. 19, 1985 issue of PC Magizine, pp256
  11. ;
  12. VECTORS        segment at 0h        ; 8088 / 80286 Interrup Vector Area
  13.     org     9h*4            ; IBM-PC Keyboard is Int 9H
  14. KB_INT_VECTOR    label    dword        ; Double word label
  15. ;
  16. VECTORS        ends
  17. ;
  18. ROM_BIOS_DATA    segment at 40h        ; Low Memory "BIOS" parameters
  19. ;
  20.     org 10h                ; Location of EQUIP_FLAG
  21. EQUIP_FLAG    dw    ?        ; Contains video settings
  22.                     ; in bits 4 & 5
  23. ;
  24.     org    17h            ; Location of KB_FLAG
  25. KB_FLAG        db    ?        ; Contains Alt )bit 3) &
  26.                     ; Right Shift (bit 0) States
  27. ROM_BIOS_DATA    ends
  28. ;
  29. ; Initialization Routine
  30. ;
  31. CODE_SEG     segment
  32.     assume    cs:CODE_SEG
  33.     org    100h            ; COM program format
  34. BEGIN:    jmp    SWAP_VECTORS        ;Initialize vectors and attach to DOS
  35. ;
  36. ROM_KB_INT    dd    ?        ; Double word to save address of
  37.                     ; ROM-BIOS keyboard interrupt
  38. VIDEO_PAGE    db    ?        ; Variable to save active video page
  39. ;
  40. FLIP_FLAG    db    ?        ; Variable to indicate video page is
  41.                     ; to be incremented. Bit map follows:
  42.                     ; hi nibble = 0: video page not flipped
  43.                     ; hi nibble = F: video page incremented
  44.                     ; low nibble = 7: monochrome mode
  45.                     ; low nibble = 3: color CRT mode
  46. ;
  47. ; DOORS_INT intercepts the keyboard interrupt and switches 
  48. ;    screens if [Alt] - [Right Shift] combination is pressed
  49. ;
  50. DOORS_INT    proc     near
  51.     assume    ds:nothing
  52.     push ds                ; Push all affected registers
  53.     push es
  54.     push ax
  55.     push bx
  56.     push cx
  57.     push dx
  58.     push si
  59.     push di
  60. ;
  61.     pushf                ; Push flags for fake interrupt call
  62.     call    ROM_KB_INT        ; to BIOS program to read keyboard
  63.     assume    ds:ROM_BIOS_DATA    ; Define data segment to read
  64.     mov    ax,ROM_BIOS_DATA    ; Keyboard flag & equipment flag
  65.     mov     ds,ax
  66. ;
  67. ; Scan keyboard for Alt - Left Shift & Alt Left Shift
  68. ;
  69.     mov    al,KB_FLAG        ; Get keyboard flag
  70.     test    al,08h            ; Alt key pressed?
  71.     jz    RETURN            ; No, quit
  72.     test    al,02h            ; Alt + Left Shift keys pressed?
  73.     jnz    FLIP_MODE        ; Yes, set FLIP_FLAG & monochrome
  74.     test    al,01h            ; Alt + Right Shift keys pressed?
  75.     jz    RETURN            ; No, quit
  76.     mov    al,00h            ; Reset FLIP_FLAG (flipping disabled)
  77.     mov    FLIP_FLAG,al        ; video page remains unchanged
  78.     jmp    VIDEO_MODE        ; Yes, continue processing
  79. ;
  80. ; FLIP_MODE sets FLIP_FLAG to indicate active video page is to be incremented
  81. ;
  82. FLIP_MODE:    
  83.     mov    al,247            ; Set FLIP_FLAG & monochrome
  84.     mov    FLIP_FLAG,al        ; Set flag, indicates that page
  85.                     ; is to be incremented
  86. ;
  87. ; VIDEO_MODE determens the current display mode (color text or monochrome)
  88. ; [Alt] + [Right Shift] or [Left Shift} are pressed -- Continue processing
  89. ; Check on video mode -- quit if not monochrome, color 80x25 or BW 80x25
  90. ;        (Can we switch screens? Not in graphics or 40 column?)
  91. ;
  92. VIDEO_MODE:
  93.     mov     ah,15            ; Call Func 15 of Int 10h to
  94.     int     10h            ; get video state of PC
  95.     mov    VIDEO_PAGE,bh        ; Save current active page
  96.     cmp    FLIP_FLAG,240
  97.     jae    FLIP_FROM_MONO
  98.     cmp    al,7            ; Is screen monochrome?
  99.     je    SCREEN_OKAY        ; Yes, go switch screens
  100. FLIP_FROM_MONO:    
  101.     cmp    al,3            ; Is screen color text?
  102.     jbe     CHECK_40_OR_80        ; Yes, go check for 80 or 40 char
  103.     jmp    RETURN            ; Screen is in graphics mode, quit
  104. CHECK_40_OR_80:
  105.     cmp    al,1            ; Is screen 40-character?
  106.     jbe     RETURN            ; Yes, quit
  107. ;
  108.     cmp    FLIP_FLAG,240        ; FLIP_FLAG set?
  109.     jae    CHANGE_PAGE        ; Yes, change active color video page
  110.     jmp    SCREEN_OKAY        ; No, continue processing DOORS_INT
  111. ;
  112. ; CHANGE_PAGE will change active color video page and exit
  113. ;
  114. CHANGE_PAGE:
  115.     inc    VIDEO_PAGE
  116.     cmp    VIDEO_PAGE, 03h        ; Check if we're on page 3 (last page)?
  117.     jbe    FLIP_PAGE        ; No, it's ok
  118.     mov    VIDEO_PAGE,00h        ; Yes, reset it to page 0
  119. FLIP_PAGE:
  120.     mov    al,VIDEO_PAGE        ; Call Func 5 of Int 10h to switch
  121.     mov    ah,5            ; active page on color CRT
  122.     int    10h
  123. ; below imported from FLIP.ASM
  124.     mov    ch,23            ; set upper left of window to row 23
  125.     mov    cl,0            ;    and column 0
  126.     mov    dh,24            ; set lower right of window to row 24
  127.     mov    dl,79            ;    and column 79
  128.     mov    al,0            ; blank the window
  129.     mov    bh,7            ; use white on black
  130.     mov    ah,6            ; perform window scroll (call to BIOS)
  131.     int    10h            ;
  132.     cmp    FLIP_FLAG,255        ; Must we switch back to monochrome?
  133.     je    SWITCH_BACK        ; Yes, switch to origional mode
  134. ;
  135. RETURN:
  136.     pop    di            ; Restore saved retisters
  137.     pop    si
  138.     pop    dx
  139.     pop    cx
  140.     pop    bx
  141.     pop    ax
  142.     pop    es
  143.     pop    ds
  144.     iret                ; Return to system
  145.  
  146. SWITCH_BACK:
  147. ;
  148. SCREEN_OKAY:
  149. ;
  150. ; Save the current cursor position of active video page
  151. ;
  152.     mov    ah,3            ; Call Func 3 of Int 10h
  153.     mov    bh,VIDEO_PAGE        ; to read cursor position
  154.     int    10h            ; of active page of color screen
  155. ;
  156. ; Screen switch routine - Establish calling argument (AL) for Int 10h
  157. ;        (Establishes which screen to switch to)
  158. ;
  159.     mov     bx, EQUIP_FLAG        ; Current equipment flag to BX
  160.     mov     cx,bx            ; Make a copy of it in CX
  161.     and    cx,30h            ; Extract screen information
  162.     xor    bx,cx            ; Erase current screen info in BX
  163.     or    bx,20h            ; Set BX to color 80x25
  164.     mov    al,3            ; Set AL for color 80x25 in Int 10h
  165.     cmp    cx,30h            ; Is current mono?
  166.     je    SET_MODE        ; Yes, switch to color
  167.     or    bx,30h            ; No, set BX for momochrome
  168.     mov    al,7            ; Set AL for monochrome in Int 10h
  169. SET_MODE:                ; Switch screens
  170.     mov    EQUIP_FLAG,bx        ; Write BX to equipment flag
  171.     xor    ah,ah            ; Use Func 0 of Int 10h to
  172.     int    10h            ; change screen parameters
  173. ;
  174. ; Restore cursor
  175. ;
  176.     mov    ah,2            ; Use Func 2 of Int 10h to restore
  177.     mov    bh,0            ; cursor on new screen (position in DX)
  178.     int    10h
  179. ;
  180.     cmp    FLIP_FLAG,255        ; Finished flipping? 
  181.     je    RETURN            ; Yes, exit bit-pattern exists
  182.     cmp    FLIP_FLAG,00h        ; Are we in flip mode?
  183.     je    COPY_SETUP        ; No, bypass flip trap
  184.     add    FLIP_FLAG,8        ; Set FLIP_FLAG to indicate screens have
  185.                     ; been switched
  186.     jmp    CHANGE_PAGE        ;
  187. ;
  188. ; After Screens are switched, set DS and ES registers to move screen data
  189. ;
  190. COPY_SETUP:
  191.     mov    ax,0b000h        ; Load ES with Mono Segment
  192.     mov    es,ax
  193.     mov    ax,0b800h        ; Load Ds with color segment
  194.     mov    ds,ax
  195.     cmp    cx,30h            ; Did we switch from mono?
  196.     jne    COPY_THE_SCREEN        ; Yes, move data from mono to color
  197.     push    ds            ;No, swap ES abd DS to move data
  198.     push    es
  199.     pop    ds
  200.     pop    es
  201. COPY_THE_SCREEN:
  202.     xor    di,di            ; Start at zero offsets
  203.     xor    si,si
  204.     mov    cx,2000            ; 2000 chars + attrs per screen
  205.     cld                ; Make sure move is 'forward'
  206. rep    movsw                ; Move Words with string instruction
  207.     jmp    RETURN            ; Exit
  208.  
  209. DOORS_INT    endp
  210. ;
  211. ; This procedure initializes the new keyboard interupt vectors
  212. ;
  213. SWAP_VECTORS    proc    near
  214.     assume    ds:VECTORS
  215.     push    ds                ; Save Data Segment
  216.                         ; for DOS return
  217.     mov    ax,VECTORS            ; Set up the data
  218.     mov    ds,ax                ; segment for vectors
  219.     cli                    ; Disable interrupts
  220.     mov    ax,WORD PTR KB_INT_VECTOR    ; Store addresses 
  221.     mov     WORD PTR ROM_KB_INT,ax            ; of BIOS program
  222.     mov    ax,WORD PTR KB_INT_VECTOR[2]
  223.     mov    WORD PTR ROM_KB_INT[2],ax
  224.     mov    WORD PTR KB_INT_VECTOR, offset DOORS_INT    ; Substitute Our
  225.     mov    WORD PTR KB_INT_VECTOR[2],cs        ; Program
  226.     sti                    ; Enable interrupts
  227.     mov     dx,offset SWAP_VECTORS        ; End of new resident
  228.                         ; program
  229.     int    27h                ; Terminate resident
  230. SWAP_VECTORS    endp
  231. CODE_SEG    ends
  232.     end    BEGIN
  233. ;
  234.